package com.zyy.array;
import java.util.Scanner;
public class BinarySearchTest {
    public static void main(String[] args){
        int[] arr = new int[]{2,4,5,6,10,15,18,20,22,25,28};
        int target;
        Scanner scan = new Scanner(System.in);
        System.out.print("请输入你要查找的数：");
        target = scan.nextInt();
        int l = 0;
        int r = arr.length - 1;
        while(l < r){
            int mid = (l + r + 1) / 2;
            if(target >= arr[mid]){
                l = mid;
            }else{
                r = mid - 1;
            }
        }
        if(arr[r] != target){
            System.out.print("没有这个数字");
        }else{
            System.out.print("这个数字位于下标：" + r);
        }
    }
}
